<template>
	<u-modal :show="show" title="修改密码" showCancelButton @confirm="confirm" @cancel="cancel">
		<u-notify ref="uNotify" message="Hi uView"></u-notify>
		<view class="slot-content">
			<u--form :model="user" ref="uForm" labelWidth="160rpx" labelAlign="left">
				<u-form-item label="原密码" prop="origiPwd" class="u-border-bottom">
					<u--input v-model="user.origiPwd" type="password" placeholder="请输入原密码" border="none"></u--input>
				</u-form-item>
				<u-form-item label="新密码" prop="newPwd" class="u-border-bottom">
					<u--input v-model="user.newPwd" type="password" placeholder="请输入新密码" border="none"></u--input>
				</u-form-item>
				<u-form-item label="确认密码" prop="confirmPwd" class="u-border-bottom">
					<u--input v-model="user.password" type="password" placeholder="请输入确认密码" border="none"></u--input>
				</u-form-item>
			</u--form>
		</view>
	</u-modal>
</template>

<script>
	
	import * as UserApi from '@/api/user';
	
	export default {

		props: {
			show: Boolean
		},
		data() {
			return {
				user:{},
				pwd: {
					origiPwd: '',
					newPwd: '',
					confirmPwd: ''
				}
			}
		},
		created(){
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.$store.dispatch('Info').then(res => {
					this.user = res.user
					this.user.password = ""
				})
			},
			confirm() {
				if(this.user.newPwd != this.user.password){
					this.$refs.uNotify.show({
						top: 10,
						type: 'warning',
						message: '二次密码不匹配',
						duration: 1000 * 3,
						safeAreaInsetTop:true
					})
					return;
				}
				UserApi.resetPwd(this.user).then(res => {
					if(res.code == 200){
						this.$refs.uNotify.show({
							top: 10,
							type: 'success',
							message: '修改成功',
							duration: 500,
							safeAreaInsetTop:true
						})
						setTimeout(() => {
							this.$store.dispatch('Logout').then(res => {
									
							  uni.reLaunch({
							    url: '/pages/login/index'
							  })
							})
						}, 500);
					}

				})
				
			},
			cancel() {
				this.$emit('close')
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>